<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: product_reviews.php 135 2013-09-22 07:30:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 135 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:30:55 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$module_smarty = new Smarty;
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');

require_once (DIR_FS_INC.'inc.row_number_format.php');
require_once (DIR_FS_INC.'inc.date_short.php');
require_once (DIR_FS_INC.'inc.break_string.php');
require_once (DIR_FS_INC.'inc.get_products_name.php');

$info_smarty->assign('options', $products_options_data);

if(isset($_SESSION['customer_first_name']))
	$name = $_SESSION['customer_first_name'].' '.$_SESSION['customer_last_name'];
else
	$name = TEXT_GUEST;

$module_smarty->assign('AUTHOR', $name);

$reviews = $db->db_query("SELECT
								(avg(reviews_rating) / 5 * 100) AS average_rating
							FROM
								".TABLE_REVIEWS."
							WHERE
								products_id = '".$product->data['products_id']."'");

$module_smarty->assign('AVERAGE','&Oslash; '.number_format($reviews->fields['average_rating'], 2).'%');

if($_SESSION['success_msg'] !='') {
	$module_smarty->assign('SUCCESS_MSG', $_SESSION['success_msg']);
	unset($_SESSION['success_msg']);

} elseif($_SESSION['error_msg'] !='') {
	$module_smarty->assign('ERROR_MSG', $_SESSION['error_msg']);
	unset($_SESSION['error_msg']);
}

if ($_SESSION['customers_status']['customers_status_write_reviews'] != 0) {
	$module_smarty->assign('BUTTON_WRITE', '<a href="javascript:void(0)">'.image_button('button_write_review.gif', IMAGE_BUTTON_WRITE_REVIEW,'style="cursor:pointer"').'</a>');

	$module_smarty->assign('FORM_ACTION_REVIEW', draw_form('product_reviews_write', href_link(FILENAME_PRODUCT_REVIEWS_WRITE, 'action=process&mode=ajax&'.product_link($product->data['products_id'],$product->data['products_name'])), 'POST', 'onsubmit="return checkForm();"'));
	
	$captcha_site = '_reviews';
	include('captcha.php');
	$module_smarty->assign('VVIMG', '<img width="200" height="70" src="captcha.php?show=true&name=reviews" alt="Captcha" />');
	$module_smarty->assign('INPUT_CODE', draw_input_field('security_code'.$captcha_site, '', 'size="6" maxlength="6"', 'text', false));
	$module_smarty->assign('INPUT_TEXT', draw_textarea_field('review', 'soft', 60, 15, $_SESSION['tmp_review'], 'style="width:99.9%"', false));
	$module_smarty->assign('INPUT_RATING', draw_radio_field('rating', '1','','class="star"').' '.
											draw_radio_field('rating', '2','','class="star"').' '.
											draw_radio_field('rating', '3','','class="star"').' '.
											draw_radio_field('rating', '4','','class="star"').' '.
											draw_radio_field('rating', '5','','class="star"'));
	$module_smarty->assign('BUTTON_SUBMIT', image_submit('button_send.gif', IMAGE_BUTTON_SEND).draw_hidden_field('get_params', $get_params));
	$module_smarty->assign('BUTTON_CANCEL', '<a href="javascript:void(0)" class="reviews_write_cancel">'.image_button('button_back.gif', IMAGE_BUTTON_CANCEL).'</a>');
	$module_smarty->assign('FORM_END', '</form>');
}

if($product->getReviewsCount() < 1)
	$module_smarty->assign('NEW_REVIEW', true);

else {
	
	$reviews_sql = "SELECT
						r.reviews_rating,
						r.reviews_id,
						r.customers_name,
						r.date_added,
						r.last_modified,
						r.reviews_read,
						rd.reviews_text
					FROM
						".TABLE_REVIEWS." r,
						".TABLE_REVIEWS_DESCRIPTION." rd
					WHERE
						r.products_id = '".$product->data['products_id']."'
					AND
						r.reviews_id = rd.reviews_id
					AND
						r.reviews_status = '1'
					AND
						rd.languages_id = '".$_SESSION['languages_id']."'
					ORDER BY
						reviews_id DESC";
	
	$listing = new page_break($reviews_sql, $_GET['page'], 5, 'product_info.php');
	$siteLinks = $listing->create('#reviews');
	
	$module_smarty->assign('TOTAL_REVIEWS', $listing->raw_sql->_numOfRows);
	$review_count = $product->getReviewsCount();
	$score = get_review_score($product->data['products_id'], $review_count);
	$module_smarty->assign('REVIEWS_COUNT', '<p>'.image('templates/'.CURRENT_TEMPLATE.'/img/stars_'.$score.'.png', $review_count.' '.TEXT_PRODUCTS_REVIEWS).' '.$score.'/<b>5</b> '.TEXT_PRODUCTS_STARS.'</p>');
	
	if($listing->result) {
		while(!$listing->sql_string->EOF) {
			if(MODULE_SEO_URL_INDEX_STATUS == 'True')
				$link = 'review-'.$listing->sql_string->fields['reviews_id'].'/'.get_url_friendly_text(get_products_name($product->data['products_id'])).'.html';
			else
				$link = href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'reviews_id='.$listing->sql_string->fields['reviews_id']);
				
			$text = substr($listing->sql_string->fields['reviews_text'], 0 , 299).' ... <a href="'.$link.'">[mehr]</a>';
			
			$data_reviews[] = array('AUTHOR' => $listing->sql_string->fields['customers_name'],
									'DATE' => date_short($listing->sql_string->fields['date_added']).$schema->ItemProp('date_puplished', $listing->sql_string->fields['date_added']),
									'RATING' => image('templates/'.CURRENT_TEMPLATE.'/img/stars_'.$listing->sql_string->fields['reviews_rating'].'.png', sprintf(TEXT_OF_5_STARS, $listing->sql_string->fields['reviews_rating']), '68', '13'),
									'REVIEW' => $schema->ItemProp('rating_amount', $listing->sql_string->fields['reviews_rating']),
									'REVIEW_SCHEMA' => $schema->ItemScope('rating'),
									'TEXT' => $text);
				$listing->sql_string->MoveNext();
		}
		
		$module_smarty->assign('NAVIGATION', $listing->getLinks());
		$module_smarty->assign('module_content', $data_reviews);
		
		$module_smarty->assign('itemscope_review', $schema->ItemScope('review'));
	}
}
$module_smarty->assign('language', $_SESSION['language']);
$module_smarty->caching = false;
$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/products_reviews.html');

$info_smarty->assign('MODULE_products_reviews', $module);
?>